﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SnailGame.Utility.DataAccess;
using System.Configuration;
using System.Collections;
using Com.Crc.PoJo.Model.Resource;

namespace Com.Crc.ResManage.DAL.EquipManage
{
    public class BroadBandManagerExchangeDAL
    {
        DataBroker broker = new DataBroker();
        /// <summary>
        /// 删除设备，修改状态位为0
        /// </summary>
        /// <param name="wlanList"></param>
        /// <returns></returns>
        public bool DeleteExchangeData(ArrayList exchangeList)
        {
            string id = "";
            for (int i = 0; i < exchangeList.Count; i++)
            {
                id += exchangeList[i] + ",";
            }
            id = id.Substring(0, id.Length - 1);
            string strSql = @"UPDATE TT_RESOURCE_EXCHANGE SET S_STATE='0' WHERE N_ID IN (" + id + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 修改交换设备信息
        /// </summary>
        /// <param name="data">model实体</param>
        /// <returns></returns>
        public bool UpdateExchangeData(Exchange data)
        {
            string strSql = @" UPDATE TT_RESOURCE_EXCHANGE
                                  SET" +
                                    "N_SUBSTATION_ID=" + data.N_SUBSTATION_ID + @",
                                    N_DEP_BRANCH_ID=" + data.N_DEP_BRANCH_ID + @",
                                    N_UNITTYPE_ID=" + data.N_UNITTYPE_ID + @",
                                    S_NAME=" + "'" + data.S_NAME + @"',
                                    N_2M=" + data.N_2M + @",
                                    N_TYPE=" + data.N_TYPE + @",
                                    S_TYPE_VALUE=" + "'" + data.S_TYPE_VALUE + @"',
                                    N_M_UP_EXCHANGE_ID=" + data.N_M_UP_EXCHANGE_ID + @",
                                    N_M_UP_EXCHANGE_PORT=" + data.N_M_UP_EXCHANGE_PORT + @",
                                    N_M_START_NO=" + data.N_M_START_NO + @",
                                    N_M_END_NO=" + data.N_M_END_NO + @",
                                    S_BAK=" + "'" + data.S_BAK + @"',
                                    S_STATE=" + "'" + data.S_STATE + @"',
                                    D_CRATE_TIME=" + "'" + data.D_CRATE_TIME.ToString("yyyy-MM-dd HH:mm:ss") + @"',
                                    WHERE N_ID=" + data.N_ID;
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 新增交换设备信息
        /// </summary>
        /// <param name="strBranchID">分局ID</param>
        /// <param name="strOfficeID">局点ID</param>
        /// <param name="strEquipID">设备ID</param>
        /// <returns></returns>
        public bool AddExchangeData(Exchange data)
        {
            string strSql = @" INSERT INTO TT_RESOURCE_EXCHANGE(N_SUBSTATION_ID,N_DEP_BRANCH_ID,N_UNITTYPE_ID,S_NAME,N_2M,N_TYPE,S_TYPE_VALUE,N_M_UP_EXCHANGE_ID,N_M_UP_EXCHANGE_PORT,N_M_START_NO,N_M_END_NO,S_BAK,S_STATE,D_CRATE_TIME)
                                    VALUES (" + 
                                                data.N_SUBSTATION_ID + "," +
                                                data.N_DEP_BRANCH_ID + "," +
                                                data.N_UNITTYPE_ID + "," +
                                                "'" + data.S_NAME + "'" + "," +
                                                data.N_2M + "," +
                                                data.N_TYPE + "," +
                                                "'" + data.S_TYPE_VALUE + "'" + "," +
                                                data.N_M_UP_EXCHANGE_ID + "," +
                                                data.N_M_UP_EXCHANGE_PORT + "," +
                                                data.N_M_START_NO + "," +
                                                data.N_M_END_NO + "," +
                                                "'" + data.S_BAK + "'" + "," +
                                                "'" + data.S_STATE + "'" + "," +
                                                "'" + data.D_CRATE_TIME.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
        /// <summary>
        /// 查询交换设备信息
        /// </summary>
        /// <param name="strBranchID">分局ID</param>
        /// <param name="strOfficeID">局点ID</param>
        /// <param name="strEquipID">设备ID</param>
        /// <returns></returns>
        public System.Data.DataTable QueryExchangeData(string strBranchID, string strOfficeID, string strEquipID)
        {
            string strSql = @" SELECT N_ID,N_SUBSTATION_ID,N_DEP_BRANCH_ID,N_UNITTYPE_ID,S_NAME,N_2M,N_TYPE,N_M_UP_EXCHANGE_ID,N_M_UP_EXCHANGE_PORT,N_M_START_NO,N_M_END_NO,S_BAK,S_STATE,D_CRATE_TIME FROM TT_RESOURCE_EXCHANGE WHERE S_STATE='1' ";
            if (strBranchID != "")
            {
                strSql += " AND N_DEP_BRANCH_ID = " + strBranchID;
            }
            if (strOfficeID != "")
            {
                strSql += " AND N_SUBSTATION_ID = " + strOfficeID;
            }
            if (strEquipID != "")
            {
                strSql += " AND N_ID = " + strEquipID;
            }
            return broker.ExecuteQueryForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
    }
}
